Take-home_Ex01

Published

February 5, 2024

1. Objective

We will be applying appropriate spatial point patterns analysis methods learned in class to discover the geographical and spatio-temporal distribution of Grab hailing services locations in Singapore.

2. Getting Started

2.1 Loading R packages

The R packages that we will be using in this exercise are as follows:

  • arrow: For reading parquet files (Grab-Posisi Dataset)

  • lubridate: To handle the date formatting

  • sf: Import, manage and process vector-based geospatial data in R.

  • tidyverse: a collection of packages for data science tasks

  • spatstat: Wide range of useful functions for point pattern analysis and derive kernel density estimation (KDE) layer.

  • spNetwork: provides functions to perform Spatial Point Patterns Analysis such as kernel density estimation (KDE) and K-function on network. It also can be used to build spatial matrices (‘listw’ objects like in ‘spdep’ package) to conduct any kind of traditional spatial analysis with spatial weights based on reticular distances.

  • tmap: Provides functions for plotting cartographic quality static point patterns maps or interactive maps by using leaflet API.

  • raster: reads, writes, manipulates, analyses and model of gridded spatial data (i.e. raster). In this hands-on exercise, it will be used to convert image output generate by spatstat into raster format.

  • maptools: Provides a set of tools for manipulating geographic data. In this take-home exercise, we mainly use it to convert Spatial objects into ppp format of spatstat.

  • # classInt, viridis, rgdal

Show code
pacman::p_load(arrow, lubridate, sf, tidyverse, spNetwork, tmap, 
               spatstat, raster, maptools)

2.2 Importing the datasets

The datasets that we will be using are as follow:

Using read_parquet() function from arrow package to import the grab data, then changing pingtimestamp column to datetime object

Show code
grab_df <- read_parquet("data/aspatial/part-00000.snappy.parquet")

grab_df$pingtimestamp <- as_datetime(grab_df$pingtimestamp)

Transforming the coordinate system at the same time when we are importing the data

Show code
sg_roads <- st_read(dsn = "data/geospatial", layer = "gis_osm_roads_free_1") %>% st_transform(crs = 3414)
Reading layer `gis_osm_roads_free_1' from data source 
  `/Users/jacksontan/Documents/Sashimii0219/IS415-GAA/Take-home_Ex/Take-home_Ex01/data/geospatial' 
  using driver `ESRI Shapefile'
Simple feature collection with 1759836 features and 10 fields
Geometry type: LINESTRING
Dimension:     XY
Bounding box:  xmin: 99.66041 ymin: 0.8021131 xmax: 119.2601 ymax: 7.514393
Geodetic CRS:  WGS 84

Transforming the coordinate system at the same time when we are importing the data

Show code
mpsz2019 <- st_read("data/geospatial", layer = "MPSZ-2019") %>% st_transform(crs = 3414)
Reading layer `MPSZ-2019' from data source 
  `/Users/jacksontan/Documents/Sashimii0219/IS415-GAA/Take-home_Ex/Take-home_Ex01/data/geospatial' 
  using driver `ESRI Shapefile'
Simple feature collection with 332 features and 6 fields
Geometry type: MULTIPOLYGON
Dimension:     XY
Bounding box:  xmin: 103.6057 ymin: 1.158699 xmax: 104.0885 ymax: 1.470775
Geodetic CRS:  WGS 84

3. Geospatial Data Wrangling

Before we begin exploring the data, we will first need to perform some data pre-processing on the datasets that we have imported.

3.1 Data Pre-processing - MPSZ2019

3.1.1 Excluding Outer Islands

As grab won’t be able to reach offshore places, we will exclude the outer islands from this dataset. We will do this through the following steps:

We will first take a look at the unique planning areas in Singapore using unique() on the PLN_AREA_N column of mpsz2019 dataset.

Show code
unique(mpsz2019$PLN_AREA_N)
 [1] "MARINA EAST"             "RIVER VALLEY"           
 [3] "SINGAPORE RIVER"         "WESTERN ISLANDS"        
 [5] "MUSEUM"                  "MARINE PARADE"          
 [7] "SOUTHERN ISLANDS"        "BUKIT MERAH"            
 [9] "DOWNTOWN CORE"           "STRAITS VIEW"           
[11] "QUEENSTOWN"              "OUTRAM"                 
[13] "MARINA SOUTH"            "ROCHOR"                 
[15] "KALLANG"                 "TANGLIN"                
[17] "NEWTON"                  "CLEMENTI"               
[19] "BEDOK"                   "PIONEER"                
[21] "JURONG EAST"             "ORCHARD"                
[23] "GEYLANG"                 "BOON LAY"               
[25] "BUKIT TIMAH"             "NOVENA"                 
[27] "TOA PAYOH"               "TUAS"                   
[29] "JURONG WEST"             "SERANGOON"              
[31] "BISHAN"                  "TAMPINES"               
[33] "BUKIT BATOK"             "HOUGANG"                
[35] "CHANGI BAY"              "PAYA LEBAR"             
[37] "ANG MO KIO"              "PASIR RIS"              
[39] "BUKIT PANJANG"           "TENGAH"                 
[41] "SELETAR"                 "SUNGEI KADUT"           
[43] "YISHUN"                  "MANDAI"                 
[45] "PUNGGOL"                 "CHOA CHU KANG"          
[47] "SENGKANG"                "CHANGI"                 
[49] "CENTRAL WATER CATCHMENT" "SEMBAWANG"              
[51] "WESTERN WATER CATCHMENT" "WOODLANDS"              
[53] "NORTH-EASTERN ISLANDS"   "SIMPANG"                
[55] "LIM CHU KANG"           
Show code
plot(mpsz2019)

Note that there are 3 areas with island in their name, mainly “NORTH-EASTERN ISLANDS”, “SOUTHERN ISLANDS”, and “WESTERN ISLANDS”.

To exclude the islands, we simply have to pass a condition to exclude these islands in the subset function.

Show code
mpsz2019_new <- subset(mpsz2019, !(PLN_AREA_N %in% 
            c("NORTH-EASTERN ISLANDS", "SOUTHERN ISLANDS", "WESTERN ISLANDS")))

Great! Now let’s check if we indeed removed the maps!

Show code
tmap_mode('plot')
before <- tm_shape(mpsz2019) +
  tm_polygons("PLN_AREA_N") +
  tmap_options(max.categories = 53)
after <- tm_shape(mpsz2019_new) +
  tm_polygons("PLN_AREA_N") +
  tmap_options(max.categories = 53)

tmap_arrange(before, after)

3.1.2 Invalid Geometries

We will be using the st_is_valid() function to test for invalid geometries.

Show code
test <- st_is_valid(mpsz2019_new,reason=TRUE)

# Number of invalid geometries
length(which(test!= "Valid Geometry"))
[1] 3
Show code
# Reason
test[which(test!= "Valid Geometry")]
[1] "Ring Self-intersection[26922.5243000389 27027.610899987]" 
[2] "Ring Self-intersection[38991.2589000446 31986.5599999869]"
[3] "Ring Self-intersection[14484.6860000313 31330.1319999856]"

We can see that there are 3 invalid geometries. Let’s fix them using st_make_valid().

Show code
mpsz2019_new<- st_make_valid(mpsz2019_new)
length(which(st_is_valid(mpsz2019_new) == FALSE))
[1] 0

3.1.3 Missing Values

Show code
mpsz2019_new[rowSums(is.na(mpsz2019_new))!=0,]
Simple feature collection with 0 features and 6 fields
Bounding box:  xmin: NA ymin: NA xmax: NA ymax: NA
Projected CRS: SVY21 / Singapore TM
[1] SUBZONE_N  SUBZONE_C  PLN_AREA_N PLN_AREA_C REGION_N   REGION_C   geometry  
<0 rows> (or 0-length row.names)

Using the code above, we can see that there are no missing values.

3.1.4 Creating boundary?

Show code
sg_boundary <- mpsz2019_new %>% st_union()
plot(sg_boundary)

3.2 Data Pre-processing - OpenStreetMap Road Dataset

3.2.1 Limiting the dataset

As the dataset contains data from Malaysia and Brunei as well, we will use st_intersection() to limit the data to only Singapore.

Show code
points_within_sg <- st_intersection(sg_roads, mpsz2019_new)

Now, we can see that in points_within_sg it only contain Singapore road data, combined with the other values from mpsz2019 like “PLN_AREA_N” used above.

Show code
colnames(points_within_sg)
 [1] "osm_id"     "code"       "fclass"     "name"       "ref"       
 [6] "oneway"     "maxspeed"   "layer"      "bridge"     "tunnel"    
[11] "SUBZONE_N"  "SUBZONE_C"  "PLN_AREA_N" "PLN_AREA_C" "REGION_N"  
[16] "REGION_C"   "geometry"  
Show code
head(points_within_sg)
Simple feature collection with 6 features and 16 fields
Geometry type: LINESTRING
Dimension:     XY
Bounding box:  xmin: 31466.72 ymin: 30680.54 xmax: 32815.21 ymax: 30873.74
Projected CRS: SVY21 / Singapore TM
        osm_id code        fclass               name  ref oneway maxspeed layer
4052  23946437 5122   residential          Rhu Cross <NA>      F       50     0
9668  32605139 5131 motorway_link               <NA> <NA>      F       40     0
20076 46337834 5131 motorway_link               <NA> <NA>      F       50    -2
21690 49961799 5111      motorway East Coast Parkway  ECP      F       70     1
26543 74722808 5111      motorway East Coast Parkway  ECP      F       70     1
29808 99007260 5131 motorway_link               <NA> <NA>      F       50     1
      bridge tunnel   SUBZONE_N SUBZONE_C  PLN_AREA_N PLN_AREA_C       REGION_N
4052       F      F MARINA EAST    MESZ01 MARINA EAST         ME CENTRAL REGION
9668       F      F MARINA EAST    MESZ01 MARINA EAST         ME CENTRAL REGION
20076      F      T MARINA EAST    MESZ01 MARINA EAST         ME CENTRAL REGION
21690      F      F MARINA EAST    MESZ01 MARINA EAST         ME CENTRAL REGION
26543      T      F MARINA EAST    MESZ01 MARINA EAST         ME CENTRAL REGION
29808      T      F MARINA EAST    MESZ01 MARINA EAST         ME CENTRAL REGION
      REGION_C                       geometry
4052        CR LINESTRING (31889.45 30760....
9668        CR LINESTRING (32768.57 30857....
20076       CR LINESTRING (32815.21 30873....
21690       CR LINESTRING (32365.45 30845....
26543       CR LINESTRING (31611.63 30720....
29808       CR LINESTRING (31611.63 30720....

3.2.2 Invalid Geometries

Again, using the st_is_valid() function to test for invalid geometries.

Show code
test <- st_is_valid(points_within_sg,reason=TRUE)

# Number of invalid geometries
length(which(test!= "Valid Geometry"))
[1] 0
Show code
# Reason
test[which(test!= "Valid Geometry")]
character(0)

No invalid geometries!

3.2.3 Missing Values / Dropping Columns

Show code
points_within_sg[rowSums(is.na(points_within_sg))!=0,]
Simple feature collection with 232766 features and 16 fields
Geometry type: GEOMETRY
Dimension:     XY
Bounding box:  xmin: 2679.373 ymin: 23099.51 xmax: 50957.8 ymax: 50220.06
Projected CRS: SVY21 / Singapore TM
First 10 features:
         osm_id code        fclass           name  ref oneway maxspeed layer
4052   23946437 5122   residential      Rhu Cross <NA>      F       50     0
9668   32605139 5131 motorway_link           <NA> <NA>      F       40     0
20076  46337834 5131 motorway_link           <NA> <NA>      F       50    -2
29808  99007260 5131 motorway_link           <NA> <NA>      F       50     1
45723 140562813 5131 motorway_link           <NA> <NA>      F       70    -1
45728 140562819 5131 motorway_link           <NA> <NA>      F       50     0
45731 140562823 5131 motorway_link           <NA> <NA>      F       60    -2
45733 140562826 5131 motorway_link           <NA> <NA>      F       40     0
52966 150819034 5141       service Bay East Drive <NA>      B        0     0
84664 174717984 5153       footway           <NA> <NA>      B        0     0
      bridge tunnel   SUBZONE_N SUBZONE_C  PLN_AREA_N PLN_AREA_C       REGION_N
4052       F      F MARINA EAST    MESZ01 MARINA EAST         ME CENTRAL REGION
9668       F      F MARINA EAST    MESZ01 MARINA EAST         ME CENTRAL REGION
20076      F      T MARINA EAST    MESZ01 MARINA EAST         ME CENTRAL REGION
29808      T      F MARINA EAST    MESZ01 MARINA EAST         ME CENTRAL REGION
45723      F      F MARINA EAST    MESZ01 MARINA EAST         ME CENTRAL REGION
45728      F      F MARINA EAST    MESZ01 MARINA EAST         ME CENTRAL REGION
45731      F      T MARINA EAST    MESZ01 MARINA EAST         ME CENTRAL REGION
45733      F      F MARINA EAST    MESZ01 MARINA EAST         ME CENTRAL REGION
52966      F      F MARINA EAST    MESZ01 MARINA EAST         ME CENTRAL REGION
84664      F      F MARINA EAST    MESZ01 MARINA EAST         ME CENTRAL REGION
      REGION_C                       geometry
4052        CR LINESTRING (31889.45 30760....
9668        CR LINESTRING (32768.57 30857....
20076       CR LINESTRING (32815.21 30873....
29808       CR LINESTRING (31611.63 30720....
45723       CR LINESTRING (32782.42 30754....
45728       CR LINESTRING (32645.37 30683....
45731       CR LINESTRING (32809.68 30108....
45733       CR LINESTRING (32609.11 30700....
52966       CR LINESTRING (32173.46 30036....
84664       CR LINESTRING (31750.06 30644....

By using the code above, we can see that majority of the missing values are in the ‘name’ and ‘ref’ column. Therefore, let’s drop the irrelevant columns first before we try it again!

Show code
sg_roads_new <- points_within_sg[c("osm_id", "code", "fclass", "PLN_AREA_N", "geometry")]

We only kept “osm_id”, “code”, “fclass”, and “PLN_AREA_N” columns.

Show code
sg_roads_new[rowSums(is.na(sg_roads_new))!=0,]
Simple feature collection with 0 features and 4 fields
Bounding box:  xmin: NA ymin: NA xmax: NA ymax: NA
Projected CRS: SVY21 / Singapore TM
[1] osm_id     code       fclass     PLN_AREA_N geometry  
<0 rows> (or 0-length row.names)

No more missing values here.

Our map so far:

Show code
tm_shape(sg_boundary) +
  tm_polygons() +
  tm_shape(sg_roads_new) +
  tm_lines("PLN_AREA_N")

3.3 Data Pre-processing - Grab-Posisi Dataset

The Grab-Posisi Dataset is an Aspatial dataset, different from the two we prepared above. As such, the pre-processing is slightly different too.

3.3.1 Getting the Origin and Destination Locations

The code below is a chain of dplyr pipes to group the trips by their id and extract the first pingtimestamp row of each trip in order to get the origin of it.

Show code
origin_df <- grab_df %>%
  group_by(trj_id) %>%
  arrange(pingtimestamp) %>% 
  filter(row_number()==1) %>% 
  mutate(weekday = wday(pingtimestamp,
                        label=TRUE,
                        abbr=TRUE),
         start_hr = factor(hour(pingtimestamp)),
         day = factor(mday(pingtimestamp)))
Show code
destination_df <- grab_df %>%
  group_by(trj_id) %>%
  arrange(desc(pingtimestamp)) %>% 
  # Same as previous code but desc, so ending location
  filter(row_number()==1) %>%
  mutate(weekday = wday(pingtimestamp,
                        label=TRUE,
                        abbr=TRUE),
         end_hr = factor(hour(pingtimestamp)),
         day = factor(mday(pingtimestamp)))

3.3.2 Converting to SF format from Dataframe

We will need the files in SF format first before we can use it for further geospatial analysis.

Show code
origin_sf <- st_as_sf(origin_df, 
                       coords = c("rawlng", "rawlat"),
                       crs=4326) %>%
  st_transform(crs = 3414)

dest_sf <- st_as_sf(destination_df, 
                       coords = c("rawlng", "rawlat"),
                       crs=4326) %>%
  st_transform(crs = 3414)

3.3.3 Invalid Geometries

Show code
test <- st_is_valid(origin_sf,reason=TRUE)
length(which(test!= "Valid Geometry"))
[1] 0
Show code
test <- st_is_valid(dest_sf,reason=TRUE)
length(which(test!= "Valid Geometry"))
[1] 0

3.3.4 Missing Files

Show code
origin_sf[rowSums(is.na(origin_sf))!=0,]
Simple feature collection with 0 features and 10 fields
Bounding box:  xmin: NA ymin: NA xmax: NA ymax: NA
Projected CRS: SVY21 / Singapore TM
# A tibble: 0 × 11
# Groups:   trj_id [0]
# ℹ 11 variables: trj_id <chr>, driving_mode <chr>, osname <chr>,
#   pingtimestamp <dttm>, speed <dbl>, bearing <int>, accuracy <dbl>,
#   weekday <ord>, start_hr <fct>, day <fct>, geometry <GEOMETRY [m]>
Show code
dest_sf[rowSums(is.na(dest_sf))!=0,]
Simple feature collection with 0 features and 10 fields
Bounding box:  xmin: NA ymin: NA xmax: NA ymax: NA
Projected CRS: SVY21 / Singapore TM
# A tibble: 0 × 11
# Groups:   trj_id [0]
# ℹ 11 variables: trj_id <chr>, driving_mode <chr>, osname <chr>,
#   pingtimestamp <dttm>, speed <dbl>, bearing <int>, accuracy <dbl>,
#   weekday <ord>, end_hr <fct>, day <fct>, geometry <GEOMETRY [m]>

No missing values, we are almost ready.

3.3.5 Removing points on the islands

Show code
origin_sf_new <- st_intersection(origin_sf, mpsz2019_new)
dest_sf_new <- st_intersection(dest_sf, mpsz2019_new)

To verify that the points that we removed is indeed from the islands, here’s a chunk of code to prove:

Show code
# Finding out points removed
diff_id <- origin_sf$trj_id[!(origin_sf$trj_id %in% origin_sf_new$trj_id)]

# Extracting full information of these points
outliers <- origin_sf[(origin_sf$trj_id %in% diff_id), ]

# Checking where these places are from
unique(st_intersection(outliers, mpsz2019)$PLN_AREA_N)
[1] "WESTERN ISLANDS"  "SOUTHERN ISLANDS"

They are indeed from “WESTERN ISLANDS” and “SOUTHERN ISLANDS”.

3.3.6 Dropping Unnecessary Columns

Now that our grab dataset is almost ready, we need to decide which column we should drop. Here are the columns in both origin_sf_new and dest_sf_new:

Show code
colnames(origin_sf_new)
 [1] "trj_id"        "driving_mode"  "osname"        "pingtimestamp"
 [5] "speed"         "bearing"       "accuracy"      "weekday"      
 [9] "start_hr"      "day"           "SUBZONE_N"     "SUBZONE_C"    
[13] "PLN_AREA_N"    "PLN_AREA_C"    "REGION_N"      "REGION_C"     
[17] "geometry"     
Show code
colnames(dest_sf_new)
 [1] "trj_id"        "driving_mode"  "osname"        "pingtimestamp"
 [5] "speed"         "bearing"       "accuracy"      "weekday"      
 [9] "end_hr"        "day"           "SUBZONE_N"     "SUBZONE_C"    
[13] "PLN_AREA_N"    "PLN_AREA_C"    "REGION_N"      "REGION_C"     
[17] "geometry"     

We will definitely be dropping the columns merged from mpsz2019_new (other than PLN_AREA_N), but what about “driving_mode”, “osname”, “speed”, “bearing”, and “accuracy”? Let’s first take a look at them.

Show code
unique(origin_sf_new$driving_mode)
[1] "car"

Seeing that there is only 1 constant in the column, it is safe for us to drop this column.

Show code
unique(origin_sf_new$osname)
[1] "ios"     "android"

There are 2 values, mainly “ios” and “android”. Arguments can be made that we can analyse the behavior of both type in terms of using grab hailing services, but that’s not what we will doing so we will drop this as well.

As we are analysing start/stop points, speed will not be a relevant factor hence we will be dropping them.

Not relevant as well, hence dropping.

According to research paper published on Grab website, this is the definition of the accuracy column:

“…the accuracy level roughly indicates the radius of the circle within which the true location lies with a certain probability. The lower the accuracy level, the more precise the reported GPS ping is.”

With that, let’s take a look at the distribution of accuracy score.

Show code
plot(origin_sf_new$accuracy)

Show code
ggplot(origin_sf_new, 
       aes(x=rownames(origin_sf_new), y=accuracy)) + 
  geom_point(size = 2)

Show code
ggplot(dest_sf_new, 
       aes(x=rownames(dest_sf_new), y=accuracy)) + 
  geom_point(size = 2)

From the plot, we can see that there are 3 clear outliers with accuracy above 180~ for origin_sf_new, and 1 for dest_sf_new. Now let’s extract these trips.

Show code
origin_sf_new[origin_sf_new$accuracy > 180, ]
Simple feature collection with 3 features and 16 fields
Geometry type: POINT
Dimension:     XY
Bounding box:  xmin: 18132.25 ymin: 30203 xmax: 28937.76 ymax: 36948.91
Projected CRS: SVY21 / Singapore TM
# A tibble: 3 × 17
  trj_id driving_mode osname pingtimestamp              speed bearing accuracy
  <chr>  <chr>        <chr>  <dttm>                     <dbl>   <int>    <dbl>
1 78815  car          ios    2019-04-21 13:20:13  0.000000101      68      200
2 67866  car          ios    2019-04-18 16:46:16 -1                13      547
3 4579   car          ios    2019-04-21 10:35:22 13.0             108      200
# ℹ 10 more variables: weekday <ord>, start_hr <fct>, day <fct>,
#   SUBZONE_N <chr>, SUBZONE_C <chr>, PLN_AREA_N <chr>, PLN_AREA_C <chr>,
#   REGION_N <chr>, REGION_C <chr>, geometry <POINT [m]>
Show code
dest_sf_new[dest_sf_new$accuracy > 500, ]
Simple feature collection with 1 feature and 16 fields
Geometry type: POINT
Dimension:     XY
Bounding box:  xmin: 33721.09 ymin: 34502.5 xmax: 33721.09 ymax: 34502.5
Projected CRS: SVY21 / Singapore TM
# A tibble: 1 × 17
  trj_id driving_mode osname pingtimestamp       speed bearing accuracy weekday
  <chr>  <chr>        <chr>  <dttm>              <dbl>   <int>    <dbl> <ord>  
1 68340  car          ios    2019-04-12 11:55:48    -1      10     1414 Fri    
# ℹ 9 more variables: end_hr <fct>, day <fct>, SUBZONE_N <chr>,
#   SUBZONE_C <chr>, PLN_AREA_N <chr>, PLN_AREA_C <chr>, REGION_N <chr>,
#   REGION_C <chr>, geometry <POINT [m]>

To ensure that our data is of utmost accuracy, we will drop these trips, before we drop the accuracy column as well (as we will not need it anymore).

Show code
origin_sf_new <- subset(origin_sf_new, accuracy < 180)
dest_sf_new <- subset(dest_sf_new, accuracy < 500)

With that done, we can now drop the columns that we don’t need.

Show code
origin_sf_new <- origin_sf_new[, c(1, 4,  8:10, 13, 17)]
dest_sf_new <- dest_sf_new[, c(1, 4,  8:10, 13, 17)]

3.3.7 Duplicated Points

Lastly, let’s check for duplicated points on the map.

Show code
# Check for any duplicates
any(duplicated(origin_sf_new))
[1] FALSE
Show code
# Count the number of duplicates
sum(multiplicity(origin_sf_new) > 1)
[1] 0

No duplicated points!

3.4 Verifying Coordinate System

It is important for the data to be in the right coordinate reference system (CRS). In this assignment, all spatial data will be projected in EPSG:3414, which is a projected coordinate system for Singapore.

Show code
st_crs(mpsz2019_new)
Coordinate Reference System:
  User input: EPSG:3414 
  wkt:
PROJCRS["SVY21 / Singapore TM",
    BASEGEOGCRS["SVY21",
        DATUM["SVY21",
            ELLIPSOID["WGS 84",6378137,298.257223563,
                LENGTHUNIT["metre",1]]],
        PRIMEM["Greenwich",0,
            ANGLEUNIT["degree",0.0174532925199433]],
        ID["EPSG",4757]],
    CONVERSION["Singapore Transverse Mercator",
        METHOD["Transverse Mercator",
            ID["EPSG",9807]],
        PARAMETER["Latitude of natural origin",1.36666666666667,
            ANGLEUNIT["degree",0.0174532925199433],
            ID["EPSG",8801]],
        PARAMETER["Longitude of natural origin",103.833333333333,
            ANGLEUNIT["degree",0.0174532925199433],
            ID["EPSG",8802]],
        PARAMETER["Scale factor at natural origin",1,
            SCALEUNIT["unity",1],
            ID["EPSG",8805]],
        PARAMETER["False easting",28001.642,
            LENGTHUNIT["metre",1],
            ID["EPSG",8806]],
        PARAMETER["False northing",38744.572,
            LENGTHUNIT["metre",1],
            ID["EPSG",8807]]],
    CS[Cartesian,2],
        AXIS["northing (N)",north,
            ORDER[1],
            LENGTHUNIT["metre",1]],
        AXIS["easting (E)",east,
            ORDER[2],
            LENGTHUNIT["metre",1]],
    USAGE[
        SCOPE["Cadastre, engineering survey, topographic mapping."],
        AREA["Singapore - onshore and offshore."],
        BBOX[1.13,103.59,1.47,104.07]],
    ID["EPSG",3414]]
Show code
st_crs(sg_roads_new)
Coordinate Reference System:
  User input: EPSG:3414 
  wkt:
PROJCRS["SVY21 / Singapore TM",
    BASEGEOGCRS["SVY21",
        DATUM["SVY21",
            ELLIPSOID["WGS 84",6378137,298.257223563,
                LENGTHUNIT["metre",1]]],
        PRIMEM["Greenwich",0,
            ANGLEUNIT["degree",0.0174532925199433]],
        ID["EPSG",4757]],
    CONVERSION["Singapore Transverse Mercator",
        METHOD["Transverse Mercator",
            ID["EPSG",9807]],
        PARAMETER["Latitude of natural origin",1.36666666666667,
            ANGLEUNIT["degree",0.0174532925199433],
            ID["EPSG",8801]],
        PARAMETER["Longitude of natural origin",103.833333333333,
            ANGLEUNIT["degree",0.0174532925199433],
            ID["EPSG",8802]],
        PARAMETER["Scale factor at natural origin",1,
            SCALEUNIT["unity",1],
            ID["EPSG",8805]],
        PARAMETER["False easting",28001.642,
            LENGTHUNIT["metre",1],
            ID["EPSG",8806]],
        PARAMETER["False northing",38744.572,
            LENGTHUNIT["metre",1],
            ID["EPSG",8807]]],
    CS[Cartesian,2],
        AXIS["northing (N)",north,
            ORDER[1],
            LENGTHUNIT["metre",1]],
        AXIS["easting (E)",east,
            ORDER[2],
            LENGTHUNIT["metre",1]],
    USAGE[
        SCOPE["Cadastre, engineering survey, topographic mapping."],
        AREA["Singapore - onshore and offshore."],
        BBOX[1.13,103.59,1.47,104.07]],
    ID["EPSG",3414]]
Show code
st_crs(origin_sf_new)
Coordinate Reference System:
  User input: EPSG:3414 
  wkt:
PROJCRS["SVY21 / Singapore TM",
    BASEGEOGCRS["SVY21",
        DATUM["SVY21",
            ELLIPSOID["WGS 84",6378137,298.257223563,
                LENGTHUNIT["metre",1]]],
        PRIMEM["Greenwich",0,
            ANGLEUNIT["degree",0.0174532925199433]],
        ID["EPSG",4757]],
    CONVERSION["Singapore Transverse Mercator",
        METHOD["Transverse Mercator",
            ID["EPSG",9807]],
        PARAMETER["Latitude of natural origin",1.36666666666667,
            ANGLEUNIT["degree",0.0174532925199433],
            ID["EPSG",8801]],
        PARAMETER["Longitude of natural origin",103.833333333333,
            ANGLEUNIT["degree",0.0174532925199433],
            ID["EPSG",8802]],
        PARAMETER["Scale factor at natural origin",1,
            SCALEUNIT["unity",1],
            ID["EPSG",8805]],
        PARAMETER["False easting",28001.642,
            LENGTHUNIT["metre",1],
            ID["EPSG",8806]],
        PARAMETER["False northing",38744.572,
            LENGTHUNIT["metre",1],
            ID["EPSG",8807]]],
    CS[Cartesian,2],
        AXIS["northing (N)",north,
            ORDER[1],
            LENGTHUNIT["metre",1]],
        AXIS["easting (E)",east,
            ORDER[2],
            LENGTHUNIT["metre",1]],
    USAGE[
        SCOPE["Cadastre, engineering survey, topographic mapping."],
        AREA["Singapore - onshore and offshore."],
        BBOX[1.13,103.59,1.47,104.07]],
    ID["EPSG",3414]]
Show code
st_crs(dest_sf_new)
Coordinate Reference System:
  User input: EPSG:3414 
  wkt:
PROJCRS["SVY21 / Singapore TM",
    BASEGEOGCRS["SVY21",
        DATUM["SVY21",
            ELLIPSOID["WGS 84",6378137,298.257223563,
                LENGTHUNIT["metre",1]]],
        PRIMEM["Greenwich",0,
            ANGLEUNIT["degree",0.0174532925199433]],
        ID["EPSG",4757]],
    CONVERSION["Singapore Transverse Mercator",
        METHOD["Transverse Mercator",
            ID["EPSG",9807]],
        PARAMETER["Latitude of natural origin",1.36666666666667,
            ANGLEUNIT["degree",0.0174532925199433],
            ID["EPSG",8801]],
        PARAMETER["Longitude of natural origin",103.833333333333,
            ANGLEUNIT["degree",0.0174532925199433],
            ID["EPSG",8802]],
        PARAMETER["Scale factor at natural origin",1,
            SCALEUNIT["unity",1],
            ID["EPSG",8805]],
        PARAMETER["False easting",28001.642,
            LENGTHUNIT["metre",1],
            ID["EPSG",8806]],
        PARAMETER["False northing",38744.572,
            LENGTHUNIT["metre",1],
            ID["EPSG",8807]]],
    CS[Cartesian,2],
        AXIS["northing (N)",north,
            ORDER[1],
            LENGTHUNIT["metre",1]],
        AXIS["easting (E)",east,
            ORDER[2],
            LENGTHUNIT["metre",1]],
    USAGE[
        SCOPE["Cadastre, engineering survey, topographic mapping."],
        AREA["Singapore - onshore and offshore."],
        BBOX[1.13,103.59,1.47,104.07]],
    ID["EPSG",3414]]

They are all in the correct CRS!

3.5 Plotting Spatial Data

Finally, plotting all three datasets together to ensure that they have a consistent projection system.

Show code
tm_shape(sg_boundary) +
  tm_polygons() +
tm_shape(sg_roads_new) + 
  tm_lines("PLN_AREA_N") + 
tm_shape(origin_sf_new) +
  tm_dots()

3.6 Exploratory Data Analysis

Before we begin our Geospatial Analysis, let’s first take a closer look at the Grab dataset.

3.6.1 Day of the Week

The distribution of the trips across all 7 days of the week looks even.

Show code
ggplot(origin_sf_new, aes(x=weekday)) + geom_bar()

Show code
ggplot(dest_sf_new, aes(x=weekday)) + geom_bar()

3.6.2 Planning Area

First let us look at the top 10 planning areas for grab ride origin points. Tampines is the Planning Area with the most origin points.

Show code
origin_pl_area <- origin_sf_new %>%
  group_by(PLN_AREA_N) %>%
  summarise(total_count=n()) %>%
  top_n(10, total_count) %>%
  .$PLN_AREA_N

ggplot(origin_sf_new[origin_sf_new$PLN_AREA_N %in% origin_pl_area,], 
       aes(x=PLN_AREA_N)) + geom_bar() +
  theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1)) +
  labs(title = "Trips Origin Distribution by Planning Area",
       x = "Planning Area",
       y = "Number of Trips")

Then for the destination points.

Show code
dest_pl_area <- dest_sf_new %>%
  group_by(PLN_AREA_N) %>%
  summarise(total_count=n()) %>%
  top_n(10, total_count) %>%
  .$PLN_AREA_N

ggplot(dest_sf_new[dest_sf_new$PLN_AREA_N %in% dest_pl_area,], 
       aes(x=PLN_AREA_N)) + geom_bar() +
  theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1)) +
  labs(title = "Trips Destination Distribution by Planning Area",
       x = "Planning Area",
       y = "Number of Trips")

6 out of 10 of the Planning Areas remains the same for destination points, mainly TAMPINES, WOODLANDS, YISHUN, QUEENSTOWN, BUKIT MERAH, and CHANGI. This time however, the Planning Area with the most destination points is Changi.

3.6.3 Starting Hour

Show code
origin_sf_new$start_hr <- factor(origin_sf_new$start_hr, levels = 0:23)

ggplot(origin_sf_new, aes(x = start_hr)) +
  geom_bar() +
  labs(title = "Trips Distribution by Start Hour",
       x = "Start Hour",
       y = "Number of Trips")

From the graph, we can see that the starting hour peaks at midnight (12am - 1am) and morning (9am - 10am), the former probably due to the lack of public transport after operating hours, and the latter from rush hour.

4. Kernel Density Estimation (KDE) Layers

4.1 Converting data format

4.1.1 Creating point ppp objects

In the code chunk below, as.ppp() function is used to derive a ppp object layer directly from a sf tibble data.frame.

Show code
origin_ppp <- as.ppp(origin_sf_new)
summary(origin_ppp)
Marked planar point pattern:  27872 points
Average intensity 2.636568e-05 points per square unit

Coordinates are given to 3 decimal places
i.e. rounded to the nearest multiple of 0.001 units

marks are of type 'character'
Summary:
   Length     Class      Mode 
    27872 character character 

Window: rectangle = [3661.47, 49845.23] x [26795.39, 49685.08] units
                    (46180 x 22890 units)
Window area = 1057130000 square units
Show code
dest_ppp <- as.ppp(dest_sf_new)
summary(dest_ppp)
Marked planar point pattern:  27820 points
Average intensity 2.642188e-05 points per square unit

Coordinates are given to 3 decimal places
i.e. rounded to the nearest multiple of 0.001 units

marks are of type 'character'
Summary:
   Length     Class      Mode 
    27820 character character 

Window: rectangle = [3638.69, 50024.92] x [26770.54, 49469.41] units
                    (46390 x 22700 units)
Window area = 1052920000 square units

4.1.2 Creating owin objects

In the code chunk as.owin() is used to create an owin object class from polygon sf tibble data.frame. In this case, we will be converting the sg_boundary polygon.

Show code
sg_boundary_owin <- as.owin(sg_boundary)

4.1.3 Combining point events object and owin object

We will now combine singapore’s boundary and the origin and destination points into one.

Show code
originSG_ppp = origin_ppp[sg_boundary_owin]
destSG_ppp = dest_ppp[sg_boundary_owin]
Show code
plot(destSG_ppp)

Show code
summary(destSG_ppp)
Marked planar point pattern:  27820 points
Average intensity 4.185996e-05 points per square unit

Coordinates are given to 3 decimal places
i.e. rounded to the nearest multiple of 0.001 units

marks are of type 'character'
Summary:
   Length     Class      Mode 
    27820 character character 

Window: polygonal boundary
37 separate polygons (29 holes)
                  vertices         area relative.area
polygon 1            12666  6.63014e+08      9.98e-01
polygon 2              285  1.61128e+06      2.42e-03
polygon 3               27  1.50315e+04      2.26e-05
polygon 4 (hole)        41 -4.01660e+04     -6.04e-05
polygon 5 (hole)       317 -5.11280e+04     -7.69e-05
polygon 6 (hole)         3 -4.14099e-04     -6.23e-13
polygon 7               30  2.80002e+04      4.21e-05
polygon 8 (hole)         4 -2.86396e-01     -4.31e-10
polygon 9 (hole)         3 -1.81439e-04     -2.73e-13
polygon 10 (hole)        3 -8.68789e-04     -1.31e-12
polygon 11 (hole)        3 -5.99535e-04     -9.02e-13
polygon 12 (hole)        3 -3.04561e-04     -4.58e-13
polygon 13 (hole)        3 -4.46076e-04     -6.71e-13
polygon 14 (hole)        3 -3.39794e-04     -5.11e-13
polygon 15 (hole)        3 -4.52043e-05     -6.80e-14
polygon 16 (hole)        3 -3.90173e-05     -5.87e-14
polygon 17 (hole)        3 -9.59850e-05     -1.44e-13
polygon 18 (hole)        4 -2.54488e-04     -3.83e-13
polygon 19 (hole)        4 -4.28453e-01     -6.45e-10
polygon 20 (hole)        4 -2.18616e-04     -3.29e-13
polygon 21 (hole)        5 -2.44411e-04     -3.68e-13
polygon 22 (hole)        5 -3.64686e-02     -5.49e-11
polygon 23              71  8.18750e+03      1.23e-05
polygon 24 (hole)        6 -8.37554e-01     -1.26e-09
polygon 25 (hole)       38 -7.79904e+03     -1.17e-05
polygon 26 (hole)        3 -3.41897e-05     -5.14e-14
polygon 27 (hole)        3 -3.65499e-03     -5.50e-12
polygon 28 (hole)        3 -4.95057e-02     -7.45e-11
polygon 29              91  1.49663e+04      2.25e-05
polygon 30 (hole)        5 -2.92235e-04     -4.40e-13
polygon 31 (hole)        3 -7.43616e-06     -1.12e-14
polygon 32 (hole)      270 -1.21455e+03     -1.83e-06
polygon 33 (hole)       19 -4.39650e+00     -6.62e-09
polygon 34 (hole)       35 -1.38385e+02     -2.08e-07
polygon 35 (hole)       23 -1.99656e+01     -3.00e-08
polygon 36              71  5.63061e+03      8.47e-06
polygon 37              10  1.99717e+02      3.01e-07
enclosing rectangle: [2667.54, 55941.94] x [21448.47, 50256.33] units
                     (53270 x 28810 units)
Window area = 664597000 square units
Fraction of frame area: 0.433

4.1.4 Rescale

The density values of the output range from 0 to 0.000035 which is way too small to comprehend, and it is computed in “number of points per square meter”. Therefore, we are going to use rescale() to covert the unit of measurement from meter to kilometer.

Show code
originSG_ppp.km <- rescale(originSG_ppp, 1000, "km")
destSG_ppp.km <- rescale(destSG_ppp, 1000, "km")

4.2 Deriving Traditional Kernel Density Estimation (KDE) Layers

4.2.1 Automatic bandwidth selection method

We will first compute the kernel density by using density() of the spatstat package, with the default method bw.diggle().

Show code
kde_originSG_bw <- density(originSG_ppp.km,
                              sigma=bw.ppl,
                              edge=TRUE,
                            kernel="gaussian") 

plot(kde_originSG_bw, main = "Kernel Density Estimation Layer")

Looking at all the different methods, we can see that bw.diggle() is still the best among the automatic bandwidth selection method.

Show code
bw.CvL(originSG_ppp.km)
   sigma 
1.542325 
Show code
bw.scott(originSG_ppp.km)
  sigma.x   sigma.y 
1.5924296 0.9284281 
Show code
bw.ppl(originSG_ppp.km)
     sigma 
0.08744077 
Show code
bw.diggle(originSG_ppp.km)
     sigma 
0.01078274 
Show code
kde_originSG_ppl <- density(originSG_ppp.km, 
                               sigma=bw.ppl, 
                               edge=TRUE,
                               kernel="gaussian")
par(mfrow=c(1,2))
plot(kde_originSG_bw, main = "bw.diggle")
plot(kde_originSG_ppl, main = "bw.ppl")

4.2.2 Computing KDE by using fixed bandwidth

Having tried automatic bandwidth selection method, let’s try computing KDE by using a fixed bandwidth defined by us. In our case, we will define a fixed bandwidth of 800m (or 0.8km).

Show code
kde_originSG_500 <- density(originSG_ppp.km, sigma=0.5, edge=TRUE, kernel="gaussian")
plot(kde_originSG_500)

4.2.3 Computing KDE by using adaptive bandwidth

Fixed bandwidth method, however, is very sensitive to highly skewed distribution of spatial point patterns over geographical units, for example urban versus rural. To overcome this, we can try using adaptive bandwidth instead.

Show code
kde_childcareSG_adaptive <- adaptive.density(originSG_ppp.km, method="kernel")
plot(kde_childcareSG_adaptive)

4.2.4 Method we are using

As the KDE layer using fixed bandwidth with gaussian kernel plots a graph that allows for meaningful analysis at a glance, we will be using that for the steps moving forward.

Show code
kde_originSG_500 <- density(originSG_ppp.km, sigma=0.5, edge=TRUE, kernel="gaussian")
plot(kde_originSG_500)

Show code
kde_destSG_500 <- density(destSG_ppp.km, sigma=0.5, edge=TRUE, kernel="gaussian")
plot(kde_destSG_500)

Show code
par(mfrow=c(1,2))
plot(kde_originSG_500, main = "Origin KDE Layer")
plot(kde_destSG_500, main = "Destination KDE layer")

4.3 Combining KDE layers

4.3.1 Converting KDE layers into grid object

In order for us to map the KDE layer of these points to our map, we first need to convert it into grid object.

Show code
gridded_kde_originSG_500 <- as.SpatialGridDataFrame.im(kde_originSG_500)
spplot(gridded_kde_originSG_500)

Show code
gridded_kde_destSG_500 <- as.SpatialGridDataFrame.im(kde_destSG_500)
spplot(gridded_kde_destSG_500)

4.3.2 Converting KDE layers into grid object

We will then convert the gridded kernel density objects into RasterLayer object by using raster() of raster package. As the RasterLayer object does not include CRS information, we will need to manually assign it to them as well.

Show code
kde_originSG_500_raster <- raster(gridded_kde_originSG_500)
projection(kde_originSG_500_raster) <- CRS("+init=EPSG:3414 +datum=WGS84 +units=km")
kde_originSG_500_raster
class      : RasterLayer 
dimensions : 128, 128, 16384  (nrow, ncol, ncell)
resolution : 0.4162063, 0.2250614  (x, y)
extent     : 2.667538, 55.94194, 21.44847, 50.25633  (xmin, xmax, ymin, ymax)
crs        : +proj=tmerc +lat_0=1.36666666666667 +lon_0=103.833333333333 +k=1 +x_0=28001.642 +y_0=38744.572 +datum=WGS84 +units=km +no_defs 
source     : memory
names      : v 
values     : -1.923671e-14, 596.2208  (min, max)
Show code
kde_destSG_500_raster <- raster(gridded_kde_destSG_500)
projection(kde_destSG_500_raster) <- CRS("+init=EPSG:3414 +datum=WGS84 +units=km")
kde_destSG_500_raster
class      : RasterLayer 
dimensions : 128, 128, 16384  (nrow, ncol, ncell)
resolution : 0.4162063, 0.2250614  (x, y)
extent     : 2.667538, 55.94194, 21.44847, 50.25633  (xmin, xmax, ymin, ymax)
crs        : +proj=tmerc +lat_0=1.36666666666667 +lon_0=103.833333333333 +k=1 +x_0=28001.642 +y_0=38744.572 +datum=WGS84 +units=km +no_defs 
source     : memory
names      : v 
values     : -7.516604e-15, 520.156  (min, max)

4.3.3 Overlaying KDE layer on tmap plot

To further explore the map, we will now be overlaying the KDE layer both onto OpenStreetMap of Singapore, and also on the Singapore Planning Area layer and OSM road layer that we have pre-processed.

4.3.3.1 Overlay on OpenStreetMap

Show code
tmap_mode("view")
tm_basemap(leaflet::providers$OpenStreetMap) +
tm_shape(kde_originSG_500_raster) + 
  tm_raster("v", alpha = 0.7,
          palette = "YlOrRd") +
  tm_layout(legend.position = c("right", "bottom"), frame = FALSE)
Show code
tmap_mode("plot")
Show code
tmap_mode("view")
tm_basemap(leaflet::providers$OpenStreetMap) +
tm_shape(kde_destSG_500_raster) + 
  tm_raster("v", alpha = 0.7,
          palette = "YlOrRd") +
  tm_layout(legend.position = c("right", "bottom"), frame = FALSE)
Show code
tmap_mode("plot")

As you can see from the plot, there are certain planning areas that are hotspots for hailing of Grab ride service, in particular Central Region (Orchard, Newton etc), Woodlands, Punggol, Tampines, and most notably Changi (where the airport lies).

4.3.3.2 Overlay on Planning Area and OSM Road Layers

To further confirm our observation, let’s plot the KDE layer over our Planning Area and OSM Road Layers.

Show code
tmap_mode("view")
tm_shape(mpsz2019_new) +
  tm_polygons("PLN_AREA_N") +
tm_shape(kde_originSG_500_raster) + 
  tm_raster("v", alpha = 0.7,
          palette = "YlOrRd")
Show code
tmap_mode("view")
tm_shape(mpsz2019_new) +
  tm_polygons("PLN_AREA_N") +
tm_shape(kde_destSG_500_raster) + 
  tm_raster("v", alpha = 0.7,
          palette = "YlOrRd")

The common overlapping Planning Areas include “TAMPINES”, “CHANGI”, “WOODLANDS”, and “NOVENA”, so let’s do a further analysis on these areas.

4.4 In-depth KDE Computation

4.4.1 Data Preparation

To do in-depth KDE computation on these 4 planning areas, we will first need to extract their respective boundaries. In the code below, we extracted their boundaries and converted them to sp’s Spatial* class.

Show code
mpsz <- as_Spatial(mpsz2019_new)
cg = mpsz[mpsz@data$PLN_AREA_N == "CHANGI",]
tp = mpsz[mpsz@data$PLN_AREA_N == "TAMPINES",]
wl = mpsz[mpsz@data$PLN_AREA_N == "WOODLANDS",]
nv = mpsz[mpsz@data$PLN_AREA_N == "NOVENA",]

Plotting down these boundaries.

Show code
par(mfrow=c(2,2))
plot(cg, main = "CHANGI")
plot(tp, main = "TAMPINES")
plot(wl, main = "WOODLANDS")
plot(nv, main = "NOVENA")

Turning the spatial point data frame into generic sp format, then into owin object as done previously.

Show code
cg_sp = as(cg, "SpatialPolygons")
tp_sp = as(tp, "SpatialPolygons")
wl_sp = as(wl, "SpatialPolygons")
nv_sp = as(nv, "SpatialPolygons")

cg_owin = as(cg_sp, "owin")
tp_owin = as(tp_sp, "owin")
wl_owin = as(wl_sp, "owin")
nv_owin = as(nv_sp, "owin")

By using the code below, we will be able to extract grab origin and destination points for these specific areas.

Show code
origin_cg_ppp = origin_ppp[cg_owin]
origin_tp_ppp = origin_ppp[tp_owin]
origin_wl_ppp = origin_ppp[wl_owin]
origin_nv_ppp = origin_ppp[nv_owin]

dest_cg_ppp = dest_ppp[cg_owin]
dest_tp_ppp = dest_ppp[tp_owin]
dest_wl_ppp = dest_ppp[wl_owin]
dest_nv_ppp = dest_ppp[nv_owin]

Next up is the rescale() function used previously as well.

Show code
origin_cg_ppp.km = rescale(origin_cg_ppp, 1000, "km")
origin_tp_ppp.km = rescale(origin_tp_ppp, 1000, "km")
origin_wl_ppp.km = rescale(origin_wl_ppp, 1000, "km")
origin_nv_ppp.km = rescale(origin_nv_ppp, 1000, "km")

dest_cg_ppp.km = rescale(dest_cg_ppp, 1000, "km")
dest_tp_ppp.km = rescale(dest_tp_ppp, 1000, "km")
dest_wl_ppp.km = rescale(dest_wl_ppp, 1000, "km")
dest_nv_ppp.km = rescale(dest_nv_ppp, 1000, "km")

Finally, we plot the four planning areas and the grab hailing origin and destination points

Show code
par(mfrow=c(2,4))
plot(origin_cg_ppp.km, main = "CHANGI ORIGIN")
plot(origin_tp_ppp.km, main = "TAMPINES ORIGIN")
plot(origin_wl_ppp.km, main = "WOODLANDS ORIGIN")
plot(origin_nv_ppp.km, main = "NOVENA ORIGIN")

plot(dest_cg_ppp.km, main = "CHANGI DESTINATION")
plot(dest_tp_ppp.km, main = "TAMPINES DESTINATION")
plot(dest_wl_ppp.km, main = "WOODLANDS DESTINATION")
plot(dest_nv_ppp.km, main = "NOVENA DESTINATION")

4.4.2 Computing KDE

We will now be computing the KDE of each planning area using the fixed bandwidth method.

Show code
par(mfrow=c(1,2))

plot(density(origin_cg_ppp.km, 
             sigma=0.5, 
             edge=TRUE, 
             kernel="gaussian"),
     main="Changi Origin")

plot(density(dest_cg_ppp.km, 
             sigma=0.5, 
             edge=TRUE, 
             kernel="gaussian"),
     main="Changi Destination")

Show code
tmap_mode('plot')
tm_shape(mpsz2019_new[mpsz2019_new$PLN_AREA_N == "CHANGI", ]) + 
  tm_polygons('SUBZONE_N')

The hotspot in Changi area is centered around Changi Airport, indicating a likely surge in use of Grab services due to the constant flow of passengers arriving and departing from Singapore.

Show code
par(mfrow=c(1,2))

plot(density(origin_tp_ppp.km, 
             sigma=0.5, 
             edge=TRUE, 
             kernel="gaussian"),
     main="Tampines Origin")

plot(density(dest_tp_ppp.km, 
             sigma=0.5, 
             edge=TRUE, 
             kernel="gaussian"),
     main="Tampines Destination")

Show code
tmap_mode('plot')
tm_shape(mpsz2019_new[mpsz2019_new$PLN_AREA_N == "TAMPINES", ]) + 
  tm_polygons('SUBZONE_N')

The hotspot in Tampines area is mainly concentrated around the stretch from Tampines West to Tampines East, encompassing the bulk of where most residents of Tampines currently live (Tampines West, Tampines, Tampines East).

Show code
par(mfrow=c(1,2))

plot(density(origin_wl_ppp.km, 
             sigma=0.5, 
             edge=TRUE, 
             kernel="gaussian"),
     main="Woodlands Origin")

plot(density(dest_wl_ppp.km, 
             sigma=0.5, 
             edge=TRUE, 
             kernel="gaussian"),
     main="Woodlands Destination")

Show code
tmap_mode('plot')
tm_shape(mpsz2019_new[mpsz2019_new$PLN_AREA_N == "WOODLANDS", ]) + 
  tm_polygons('SUBZONE_N')

The rides are concentrated around the lower half of Woodlands area, ranging from Woodlands West to Woodlands South, then Woodlands East. However, one prominent hotspot shared across both the origin and destination map is the Woodlands West region, indicating that this might either be the area with the wealthiest residents in Woodlands, or that there are just more residents concentrated here.

Show code
par(mfrow=c(1,2))

plot(density(origin_nv_ppp.km, 
             sigma=0.5, 
             edge=TRUE, 
             kernel="gaussian"),
     main="Novena Origin")

plot(density(dest_nv_ppp.km, 
             sigma=0.5, 
             edge=TRUE, 
             kernel="gaussian"),
     main="Novena Destination")

Show code
tmap_mode('plot')
tm_shape(mpsz2019_new[mpsz2019_new$PLN_AREA_N == "NOVENA", ]) + 
  tm_polygons('SUBZONE_N')

The Novena area’s notable hotspots present an interesting distinction. Origin points predominantly converge around the affluent Moulmein area, revealing a concentration in the wealthier section of town. Conversely, the destination points gravitate towards the Malcolm area, characterized by a cluster of prestigious schools, as illustrated in the figure below.

Moulmein Area

Google Map View of Malcolm Area, characterized by Prestigious Schools

4.5 Nearest Neighbour Analysis

In this section, we will perform the Clark-Evans test of aggregation for a spatial point pattern by using clarkevans.test() of statspat package, to test whether the distribution of Grab ride hailing origin points are randomly distributed.

Using 95% confidence interval, the test hypotheses are:

Ho = The distribution of Grab ride hailing origin points are randomly distributed.

H1= The distribution of Grab ride hailing origin points are not randomly distributed.

For this section, we will be making use of the ppp object.

Clark-Evans Test

Show code
clarkevans.test(originSG_ppp,
                correction="none",
                clipregion="sg_owin",
                alternative=c("clustered"),
                nsim=99)

    Clark-Evans test
    No edge correction
    Z-test

data:  originSG_ppp
R = 0.28008, p-value < 2.2e-16
alternative hypothesis: clustered (R < 1)
Show code
clarkevans.test(origin_cg_ppp,
                correction="none",
                clipregion="sg_owin",
                alternative=c("clustered"),
                nsim=99)

    Clark-Evans test
    No edge correction
    Z-test

data:  origin_cg_ppp
R = 0.11647, p-value < 2.2e-16
alternative hypothesis: clustered (R < 1)
Show code
clarkevans.test(origin_tp_ppp,
                correction="none",
                clipregion="sg_owin",
                alternative=c("clustered"),
                nsim=99)

    Clark-Evans test
    No edge correction
    Z-test

data:  origin_tp_ppp
R = 0.31668, p-value < 2.2e-16
alternative hypothesis: clustered (R < 1)
Show code
clarkevans.test(origin_wl_ppp,
                correction="none",
                clipregion="sg_owin",
                alternative=c("clustered"),
                nsim=99)

    Clark-Evans test
    No edge correction
    Z-test

data:  origin_wl_ppp
R = 0.31908, p-value < 2.2e-16
alternative hypothesis: clustered (R < 1)
Show code
clarkevans.test(origin_nv_ppp,
                correction="none",
                clipregion="sg_owin",
                alternative=c("clustered"),
                nsim=99)

    Clark-Evans test
    No edge correction
    Z-test

data:  origin_nv_ppp
R = 0.35838, p-value < 2.2e-16
alternative hypothesis: clustered (R < 1)

Having performed the Clark-Evans Test on all 4 planning area and Singapore as a whole, all of their p-values are <2.2e-16 < 0.05, thus we reject Ho. This means that the distribution of Grab ride hailing origin points are not randomly distributed which we explored in earlier sections.

Furthermore, as their R value ranges from 0.11647 to 0.35838 which is <1, this suggests that the points are clustering.

5. Network Kernel Density Estimation (NKDE) Layers

In this section, we will be using appropriate functions of spNetwork package:

  • to derive network constrained kernel density estimation (NetKDE), and
  • to perform network G-function and k-function analysis,

where in this case the network refers to OSM’s Road Map of Singapore.

However, due to limitations in computational power, we will be limiting the area of scope down to the 4 areas identified in the previous section, Changi, Tampines, Woodlands, and Novena, and only the Origin points.

5.1 Data Preparation

5.1.1 Initial Data Pre-processing

Before we begin, let us first convert our sg_roads_new data from SFC_GEOMETRY to SFC_LINESTRING.

Show code
sg_roads_linestring <- st_cast(sg_roads_new, "LINESTRING")

5.1.2 Narrowing down the scope

Then, let us narrow down the scope of our data to the 4 areas mentioned.

Show code
# Roads
cg_roads <- sg_roads_linestring %>% filter(PLN_AREA_N == "CHANGI")
tp_roads <- sg_roads_linestring %>% filter(PLN_AREA_N == "TAMPINES")
wl_roads <- sg_roads_linestring %>% filter(PLN_AREA_N == "WOODLANDS")
nv_roads <- sg_roads_linestring %>% filter(PLN_AREA_N == "NOVENA")

# Grab Origin Points
cg_origin <- origin_sf_new %>% filter(PLN_AREA_N == "CHANGI")
tp_origin <- origin_sf_new %>% filter(PLN_AREA_N == "TAMPINES")
wl_origin <- origin_sf_new %>% filter(PLN_AREA_N == "WOODLANDS")
nv_origin <- origin_sf_new %>% filter(PLN_AREA_N == "NOVENA")

5.1.3 Visualising the data

Before we begin our analysis, let us visualise our geospatial data to make sure everything falls into place.

Show code
tm_shape(cg_roads) +
  tm_lines("PLN_AREA_N") +
tm_shape(cg_origin) +
  tm_dots()

Show code
tm_shape(tp_roads) +
  tm_lines("PLN_AREA_N") +
tm_shape(tp_origin) +
  tm_dots()

Show code
tm_shape(wl_roads) +
  tm_lines("PLN_AREA_N") +
tm_shape(wl_origin) +
  tm_dots()

Show code
tm_shape(nv_roads) +
  tm_lines("PLN_AREA_N") +
tm_shape(nv_origin) +
  tm_dots()

5.2 Network Constrained KDE (NetKDE) Analysis

We will now perform NetKDE analysis by using appropriate functions provided in spNetwork package.

5.2.1 Preparing the lixels objects

Before we can compute NetKDE, the SpatialLines object need to be cut into lixels with a specified minimal distance, and this can be done using lixelize_lines() of spNetwork package.

Show code
cg_lixels <- lixelize_lines(cg_roads, 
                         700, 
                         mindist = 350)

tp_lixels <- lixelize_lines(tp_roads, 
                         700, 
                         mindist = 350)

wl_lixels <- lixelize_lines(wl_roads, 
                         700, 
                         mindist = 350)

nv_lixels <- lixelize_lines(nv_roads, 
                         700, 
                         mindist = 350)

5.2.2 Generating line centre points

Next, we will use lines_center() of spNetwork to generate a SpatialPointsDataFrame (i.e. samples) with line centre points.

Show code
cg_lines_center <- lines_center(cg_lixels)
tp_lines_center <- lines_center(tp_lixels)
wl_lines_center <- lines_center(wl_lixels)
nv_lines_center <- lines_center(nv_lixels)

5.2.3 Computing NetKDE

We are now ready to compute NetKDE. As the code is fairly long, we will split it into 4 tabs.

Show code
# Origin
cg_o_densities <- nkde(cg_roads, 
                  events = cg_origin,
                  w = rep(1,nrow(cg_origin)),
                  samples = cg_lines_center,
                  kernel_name = "quartic", # kernel method
                  bw = 300, 
                  div= "bw", 
                  method = "simple", 
                  # method used to calculate NKDE. spNetwork supports 3 popular                                     methods, namely simple, discontinuous, and continuous
                  digits = 1, 
                  tol = 1,
                  grid_shape = c(1,1), 
                  max_depth = 8,
                  agg = 5, 
                  # we aggregate events within a 5m radius (faster calculation)
                  sparse = TRUE,
                  verbose = FALSE)
Show code
tp_o_densities <- nkde(tp_roads, 
                  events = tp_origin,
                  w = rep(1,nrow(tp_origin)),
                  samples = tp_lines_center,
                  kernel_name = "quartic", # kernel method
                  bw = 300, 
                  div= "bw", 
                  method = "simple", 
                  # method used to calculate NKDE. spNetwork supports 3 popular                                     methods, namely simple, discontinuous, and continuous
                  digits = 1, 
                  tol = 1,
                  grid_shape = c(1,1), 
                  max_depth = 8,
                  agg = 5, 
                  # we aggregate events within a 5m radius (faster calculation)
                  sparse = TRUE,
                  verbose = FALSE)
Show code
wl_o_densities <- nkde(wl_roads, 
                  events = wl_origin,
                  w = rep(1,nrow(wl_origin)),
                  samples = wl_lines_center,
                  kernel_name = "quartic", # kernel method
                  bw = 300, 
                  div= "bw", 
                  method = "simple", 
                  # method used to calculate NKDE. spNetwork supports 3 popular                                     methods, namely simple, discontinuous, and continuous
                  digits = 1, 
                  tol = 1,
                  grid_shape = c(1,1), 
                  max_depth = 8,
                  agg = 5, 
                  # we aggregate events within a 5m radius (faster calculation)
                  sparse = TRUE,
                  verbose = FALSE)
Show code
nv_o_densities <- nkde(nv_roads, 
                  events = nv_origin,
                  w = rep(1,nrow(nv_origin)),
                  samples = nv_lines_center,
                  kernel_name = "quartic", # kernel method
                  bw = 300, 
                  div= "bw", 
                  method = "simple", 
                  # method used to calculate NKDE. spNetwork supports 3 popular                                     methods, namely simple, discontinuous, and continuous
                  digits = 1, 
                  tol = 1,
                  grid_shape = c(1,1), 
                  max_depth = 8,
                  agg = 5, 
                  # we aggregate events within a 5m radius (faster calculation)
                  sparse = TRUE,
                  verbose = FALSE)

5.2.4 Reinsert Density

Before we are able to visualise, we first need to insert the computed values back into lines_center and lixels objects as density field.

Show code
cg_lines_center$o_density <- cg_o_densities
cg_lixels$o_density <- cg_o_densities

tp_lines_center$o_density <- tp_o_densities
tp_lixels$o_density <- tp_o_densities

wl_lines_center$o_density <- wl_o_densities
wl_lixels$o_density <- wl_o_densities

nv_lines_center$o_density <- nv_o_densities
nv_lixels$o_density <- nv_o_densities

Since svy21 projection system is in meter, the computed density values are very small i.e. 0.0000005. We will thus need to rescale the density values from number of events per meter to number of events per kilometer.

Show code
cg_lines_center$o_density <- cg_lines_center$o_density*1000
cg_lixels$o_density <- cg_lixels$o_density*1000

tp_lines_center$o_density <- tp_lines_center$o_density*1000
tp_lixels$o_density <- tp_lixels$o_density*1000

wl_lines_center$o_density <- wl_lines_center$o_density*1000
wl_lixels$o_density <- wl_lixels$o_density*1000

nv_lines_center$o_density <- nv_lines_center$o_density*1000
nv_lixels$o_density <- nv_lixels$o_density*1000

5.2.5 Visualising NetKDE

Show code
tmap_mode('view')
tm_basemap(leaflet::providers$OpenStreetMap) +
tm_shape(cg_lixels)+
  tm_lines(col="o_density")+
tm_shape(cg_origin)+
  tm_dots(alpha=0.2)
Show code
tmap_mode('plot')

This tmap plot further reinforces our observation above that the grab ride traffic are from incoming tourists or locals returning home form the airport, as you can see the denser area being the Changi Airport Terminals. However, it is worth highlighting that there some slight traffic along the Changi Village area and infront of the Japanese School as well.

Show code
tmap_mode('view')
tm_basemap(leaflet::providers$OpenStreetMap) +
tm_shape(tp_lixels)+
  tm_lines(col="o_density")+
tm_shape(tp_origin)+
  tm_dots(alpha=0.2)
Show code
tmap_mode('plot')

As we have discovered earlier, a huge portion of the grab rides indeed originated from Tampines East, one of the more populated area of Tampines. Particularly along Tampines Avenue 2, there seems to be a higher density, presumably due to it being more convenient to get a ride along the main road.

Surprisingly, the other higher density area in this network density map is the area around Changi General Hospital.

Show code
tmap_mode('view')
tm_basemap(leaflet::providers$OpenStreetMap) +
tm_shape(wl_lixels)+
  tm_lines(col="o_density")+
tm_shape(wl_origin)+
  tm_dots(alpha=0.2)
Show code
tmap_mode('plot')

There are 3 main points of to focus on with higher density, mainly:

  • Along the route to Woodlands Checkpoint, showing that a significant portion of the rides in Woodlands are people coming in from Malaysia.

  • Around the main hub of Woodlands, along the Woodlands MRT stretch. No surprises here, as the area is perhaps the most dense in terms of human traffic due to concentration of malls, bus interchange, and MRT station.

  • 3 different points around the Sembawang Air Base, which I assume is the entrance. This make sense as well, as military bases in Singapore are generally more inaccessible.

Show code
tmap_mode('view')
tm_basemap(leaflet::providers$OpenStreetMap) +
tm_shape(nv_lixels)+
  tm_lines(col="o_density")+
tm_shape(nv_origin)+
  tm_dots(alpha=0.2)
Show code
tmap_mode('plot')

Network KDE indicates that the majority of the traffic is along Moulmein Road, which is the main road next to several of the moderately wealthier estates in Singapore.

5.3 Network Constrained G- and K-Function Analysis

We are now going to perform complete spatial randomness (CSR) test by using kfunctions() of spNetwork package. The null hypothesis is defined as:

  • The observed spatial point events (i.e distribution of Grab ride hailing points) are uniformly distributed over a street network in the 4 Planning Area specified above.

The CSR test is based on the assumption of the binomial point process which implies the hypothesis that the childcare centres are randomly and independently distributed over the street network.

If this hypothesis is rejected, we may infer that the distribution of Grab ride hailing points are spatially interacting and dependent on each other; as a result, they may form nonrandom patterns.

Show code
kfun_cg <- kfunctions(cg_roads, 
                             cg_origin[c("trj_id","PLN_AREA_N", "geometry")],
                             start = 0,
                             # A double, the start value for evaluating the k and                                  g functions.
                             end = 1000, 
                             #  A double, the last value for evaluating the k                                 and g functions.
                             step = 50, 
                             # A double, the jump between two evaluations of the                               k and g function
                             width = 50,
                             # The width of each donut for the g-function
                             nsim = 50,
                             # number of Monte Carlo simulations required.
                             resolution = 50,
                             verbose = FALSE,
                             agg = 5,
                             conf_int = 0.05
                             #  A double indicating the width confidence interval                               (default = 0.05).
                             )

kfun_cg
$plotk


$plotg


$values
       obs_k    lower_k    upper_k    obs_g    lower_g   upper_g distances
1    0.00000   0.000000   0.000000 14.86145  0.4666575  0.740489         0
2   36.75689   2.027349   2.523346 43.40340  2.4061742  2.891653        50
3   79.23030   4.792789   5.565200 41.90507  2.8875935  3.651886       100
4  121.95096   7.772828   9.299568 42.98638  3.2411387  4.192353       150
5  166.35078  11.183174  13.675336 47.23408  3.7570638  4.744259       200
6  214.49640  15.486794  18.645635 49.64395  4.2047155  5.230292       250
7  264.37654  20.154292  23.852124 49.89859  4.4174700  5.863389       300
8  316.81416  24.897813  29.586347 52.19405  4.9863531  6.185934       350
9  369.73892  30.336800  35.754382 54.99879  5.4725700  6.650008       400
10 423.85570  36.210522  42.276517 52.66643  5.9375669  7.328313       450
11 477.36355  42.523223  49.538771 55.36046  6.2578980  7.861399       500
12 531.87151  49.280255  57.486527 54.89546  6.7404245  8.309235       550
13 587.96637  56.497301  65.593894 55.21653  7.4170687  8.740465       600
14 643.18290  64.142624  74.543792 55.12058  7.7444117  9.705333       650
15 698.60978  72.400193  84.237315 53.94332  7.8931369 10.119955       700
16 749.05825  80.872731  94.775583 53.11297  8.3433720 10.749731       750
17 802.93515  89.886289 105.839187 49.17157  8.6216320 11.201995       800
18 852.30969  99.165744 117.035277 50.21966  9.2870203 11.736557       850
19 900.47377 108.683048 128.865019 47.30420  9.5591911 12.188084       900
20 946.48263 118.736944 141.281357 45.53648 10.1415443 12.501588       950
21 991.41387 129.521181 154.070062 42.06376 10.3893581 12.972305      1000

The blue line represents the empirical network K-function of the Grab ride hailing origin points in Changi planning area. The gray envelop represents the results of the 50 simulations in the interval 2.5% - 97.5%. Because the blue line is above the gray area, we can infer that these origin points in Changi planning area are in clusters, which reinforces our observations made above.

Show code
kfun_tp <- kfunctions(tp_roads, 
                             tp_origin[c("trj_id","PLN_AREA_N", "geometry")],
                             start = 0,
                             # A double, the start value for evaluating the k and                                  g functions.
                             end = 1000, 
                             #  A double, the last value for evaluating the k                                 and g functions.
                             step = 50, 
                             # A double, the jump between two evaluations of the                               k and g function
                             width = 50,
                             # The width of each donut for the g-function
                             nsim = 50,
                             # number of Monte Carlo simulations required.
                             resolution = 50,
                             verbose = FALSE,
                             agg = 10,
                             conf_int = 0.05
                             #  A double indicating the width confidence interval                               (default = 0.05).
                             )

kfun_tp
$plotk


$plotg


$values
       obs_k    lower_k    upper_k     obs_g    lower_g    upper_g distances
1    0.00000   0.000000   0.000000  3.544369  0.5025507  0.6765691         0
2   10.43806   1.663994   1.949098 14.896712  1.8908889  2.4198014        50
3   26.84334   3.859644   4.487299 17.212894  2.4333632  3.0265803       100
4   44.52556   6.707482   7.766983 17.877273  3.0079899  3.7823872       150
5   63.16474  10.183280  11.728418 19.330982  3.6828828  4.5352990       200
6   82.52925  14.177476  16.721010 18.724508  4.2366333  5.3691248       250
7  102.07051  19.084583  22.442896 20.833454  5.0983447  6.3643214       300
8  122.50168  24.557936  28.783141 20.988882  5.7032951  7.1440521       350
9  144.84065  30.848658  36.368639 22.921066  6.6305300  8.1269059       400
10 167.65810  37.932672  44.903010 22.872304  7.6156696  9.3011496       450
11 190.66450  46.125559  54.745720 23.615920  8.4697619 10.3231652       500
12 215.64575  55.318213  65.469494 25.459724  9.3695684 11.6689892       550
13 241.81557  65.555131  77.495815 26.828100 10.6097928 12.8008711       600
14 268.85090  76.502904  90.551618 27.711907 11.5681134 14.1105810       650
15 297.63862  88.618368 105.227226 29.711138 12.6369098 15.4402527       700
16 329.33375 101.950742 120.940240 31.756083 13.4551927 16.5547632       750
17 360.65707 116.363036 138.147344 32.469224 14.7775502 17.8976920       800
18 393.75715 131.554452 156.461644 35.346167 15.5731284 18.8945649       850
19 429.61227 147.849101 175.995445 35.693594 16.4439826 20.2742173       900
20 466.66205 164.802492 196.295414 39.131297 17.3419606 21.1603096       950
21 506.48820 182.834888 217.578542 39.405581 18.5294613 22.3173343      1000

Similar to Changi planning area, as the blue line is above the grey area, we can infer that the Tampines planning area consists of mainly origin points in clusters.

Show code
kfun_wl <- kfunctions(wl_roads, 
                             wl_origin[c("trj_id","PLN_AREA_N", "geometry")],
                             start = 0,
                             # A double, the start value for evaluating the k and                                  g functions.
                             end = 1000, 
                             #  A double, the last value for evaluating the k                                 and g functions.
                             step = 50, 
                             # A double, the jump between two evaluations of the                               k and g function
                             width = 50,
                             # The width of each donut for the g-function
                             nsim = 50,
                             # number of Monte Carlo simulations required.
                             resolution = 50,
                             verbose = FALSE,
                             agg = 5,
                             conf_int = 0.05
                             #  A double indicating the width confidence interval                               (default = 0.05).
                             )

kfun_wl
$plotk


$plotg


$values
        obs_k    lower_k    upper_k    obs_g    lower_g   upper_g distances
1     0.00000   0.000000   0.000000 12.80481  0.8216355  1.190549         0
2    30.08326   2.714612   3.297066 35.47919  3.4162738  4.204424        50
3    67.77057   6.716210   8.054094 39.66965  4.5038788  5.566418       100
4   108.36633  11.943373  13.909825 41.09708  5.5168593  6.555863       150
5   149.89203  17.996763  21.344536 42.13034  6.4737756  8.191288       200
6   193.36561  25.287199  29.933056 44.11650  7.7433498  9.561701       250
7   237.89542  33.543163  40.506973 45.81948  9.1135714 11.721030       300
8   285.19973  43.569641  53.005820 47.25456 10.7419174 13.406588       350
9   332.27061  55.127071  67.588988 48.52127 12.0667902 15.233550       400
10  383.29084  68.030613  83.965442 52.89924 14.2974903 17.670520       450
11  437.26544  83.169256 102.457980 54.76294 15.8079678 19.981202       500
12  492.18911 100.285067 122.305433 55.70436 18.2502955 22.169041       550
13  547.99297 119.854303 144.802057 57.94692 19.9140403 24.668007       600
14  608.33170 141.177025 170.022094 60.72525 21.9834366 27.591376       650
15  669.64247 164.449171 197.927659 62.01109 24.3668300 29.650440       700
16  732.69448 189.755887 229.248732 64.49475 26.6007830 33.255954       750
17  799.31698 217.677334 263.172479 68.91482 28.5394906 36.061454       800
18  871.09049 247.861052 300.575453 73.95102 31.7822144 38.662407       850
19  945.99058 280.115123 340.905241 76.33518 33.3556444 41.635908       900
20 1024.72905 314.307710 383.040559 81.14559 35.3934688 42.709736       950
21 1109.01653 351.072740 427.204709 86.31191 37.4701361 45.535137      1000

Similar to Changi planning area, as the blue line is above the grey area, we can infer that the Woodlands planning area consists of mainly origin points in clusters.

Show code
kfun_nv <- kfunctions(nv_roads, 
                             nv_origin[c("trj_id","PLN_AREA_N", "geometry")],
                             start = 0,
                             # A double, the start value for evaluating the k and                                  g functions.
                             end = 1000, 
                             #  A double, the last value for evaluating the k                                 and g functions.
                             step = 50, 
                             # A double, the jump between two evaluations of the                               k and g function
                             width = 50,
                             # The width of each donut for the g-function
                             nsim = 50,
                             # number of Monte Carlo simulations required.
                             resolution = 50,
                             verbose = FALSE,
                             agg = 5,
                             conf_int = 0.05
                             #  A double indicating the width confidence interval                               (default = 0.05).
                             )

kfun_nv
$plotk


$plotg


$values
        obs_k    lower_k    upper_k     obs_g    lower_g   upper_g distances
1    0.000000  0.0000000  0.0000000  2.070894 0.09225552 0.1942221         0
2    4.899254  0.3226515  0.5243998  5.799959 0.43432927 0.6678814        50
3   10.932279  0.8271436  1.1927667  5.931059 0.54709950 0.8759419       100
4   16.831777  1.4766952  2.0144478  5.841231 0.70624027 0.9963596       150
5   22.590463  2.3080874  3.1064618  6.110714 0.87836965 1.1944662       200
6   28.919677  3.4388245  4.4197677  6.732225 1.08934345 1.5553552       250
7   36.047630  4.7541939  6.0819451  7.460558 1.33964724 1.8186476       300
8   43.869927  6.2384153  8.0355771  8.091780 1.61422880 2.1687330       350
9   52.602640  8.0705371 10.3696417  8.999769 1.80262428 2.4826446       400
10  61.765070 10.0171285 13.0232018  9.453763 2.00485809 2.9185519       450
11  70.978483 12.1084154 15.9646961  9.152719 2.26001743 2.9984257       500
12  80.264729 14.4423587 19.1615926  9.232835 2.49004928 3.3141581       550
13  89.281492 17.1032021 22.6253018  9.490180 2.63134590 3.5617914       600
14  99.725788 20.0541648 26.4664089 10.415163 2.97754687 3.9319059       650
15 110.301184 23.1637827 30.3906673 11.077946 3.30505396 4.1990828       700
16 121.383985 26.5987227 34.8417533 11.230896 3.55377969 4.6740773       750
17 132.750836 30.2589604 39.4643618 11.612056 3.73695545 4.8937911       800
18 144.807176 34.0448356 44.4415470 11.956801 3.98871591 5.2097663       850
19 156.674149 38.3231853 49.9291723 12.357384 4.12236502 5.5197934       900
20 169.582638 42.8815790 55.6176962 13.102711 4.45958322 5.5540250       950
21 182.794599 47.4041630 61.2769653 13.190111 4.60039428 5.8913646      1000

Similar to Changi planning area, as the blue line is above the grey area, we can infer that the Novena planning area consists of mainly origin points in clusters.

The results of our G- and K-Function Analysis on all four planning area shows a spatial pattern of clustering among the grab origin points, which supports the idea that grab rides are commonly booked at the same location within an area, possibly due to designated pickup points or taxi stands.

6. Conclusion

In conclusion, our analysis of Grab ride-hailing origin points in the specific planning areas of Changi, Tampines, Woodlands, and Novena, and also the whole of Singapore uncovered noteworthy spatial patterns. The observed clustering of origin points within these areas suggests a localized preference for specific pickup locations, potentially driven by factors such as designated pickup points, popular landmarks, transportation hubs, or simply area with higher population density.

These findings hold practical implications for both Grab and urban planners as the identified clusters can guide Grab in optimizing their service by strategically placing vehicles or promoting the use of specific pickup points, ultimately enhancing the efficiency and user experience. Urban planners, on the other hand, can leverage this information to make informed decisions regarding infrastructure development, such as improving the accessibility of popular pickup locations or adjusting traffic flow in areas with high ride-hailing activity.

Moreover, understanding the spatial dynamics of Grab ride-hailing services contributes to a broader perspective on urban mobility patterns. This knowledge can be valuable for city officials, transportation authorities, and policymakers in crafting policies that support sustainable and efficient transportation solutions. By aligning urban planning efforts with the observed ride-hailing patterns, cities can work towards creating more resilient, user-friendly, and accessible transportation systems.

In essence, our analysis not only sheds light on the localized behaviors of Grab users but also opens avenues for strategic decision-making that can enhance the overall urban mobility landscape. As technology continues to shape the future of transportation, such spatial insights play a crucial role in fostering innovation and creating urban environments that are responsive to the evolving needs of their residents.